package com.xnyzc.lhy.order.controller.capi.vehicle.collect;


import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.vehicle.OaSysVehicle;
import com.xnyzc.lhy.order.service.vehicle.collect.IOaCVehicleCollectService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户车辆收藏 前端控制器
 * </p>
 *
 * @author bin
 * @since 2019-07-18
 */
@RestController
@RequestMapping("oa/vehicle/collect")
public class OaVehicleCollectController {

    @Autowired
    private IOaCVehicleCollectService iOaCVehcileCollectService;

    /**
     * 查询全部用户车辆收藏列表
     * @param current 当前页
     * @return
     */
    @ApiOperation(value = "根据乘客端用户id查询全部收藏的车辆信息", notes = "根据乘客端用户id查询全部收藏的车辆信息")
    @GetMapping(value = "selectVehicleCollectPage")
    public Rv selectVehicleCollectPage (
            @ApiParam(name = "current", value = "分页当前页") @RequestParam(value = "current") long current,
            @ApiParam(name = "vehNo", value = "车牌号") @RequestParam(value = "vehNo", required = false) String vehNo
    ){
        long userId = TokenUtil.getTokenUserId();
        if (userId == 0){
            PangException.create(EErrorCode.tokenExpire);
        }
        return Rv.wrap(iOaCVehcileCollectService.selectVehicleCollectPage(userId, current, vehNo));
    }

    /**
     * 收藏车辆
     * @param oaSysVehicle 收藏入参实体
     * @return
     */
    @ApiOperation(value = "收藏车辆", notes = "收藏车辆")
    @PostMapping(value = "insertCollectVehicle")
    public Rv insertCollectVehicle(
            @ApiParam(name = "paramVehcileCollect", value = "收藏入参实体") @RequestBody OaSysVehicle oaSysVehicle
    ){
        long userId = TokenUtil.getTokenUserId();
        if (userId == 0){
            PangException.create(EErrorCode.tokenExpire);
        }
        return Rv.wrap(iOaCVehcileCollectService.collectVehicle(userId, oaSysVehicle.getVehicleId()));
    }
}
